package com.example.jdshopdetailtwo.fragment;

import android.util.Log;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.jdshopdetailtwo.R;
import com.example.jdshopdetailtwo.adapter.BodyDetailAdapter;
import com.example.jdshopdetailtwo.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author: njb
 * @date: 2020/3/24 0024 10:47
 * @desc: 详情
 */
public class FMBodyDetail extends BaseFragment {
    private static final String imgUrl = "<img src=\"/popWaterMark/jfs/t1/76756/21/7090/87973/5d512c63Ef0646fe3/32b230921e6cb495.jpg\" alt=\"\" />" +
            "<img src=\"popWaterMark/jfs/t1/38653/28/7491/85619/5d512c63E1b1cf20b/e61900781e549b52.jpg\" alt=\"\" />" +
            "<img src=\"popWaterMark/jfs/t1/81805/33/8314/223355/5d63a5feEe675211a/343cd36803c784d6.jpg\" alt=\"\" />" +
            "<img src=\"popWaterMark/jfs/t1/65523/18/6037/85318/5d4132a4E9e24ec23/19072d835537b84e.jpg\" alt=\"\" />" +
            "<img src=\"popWaterMark/jfs/t1/73579/9/10573/109217/5d809ecaE8f711868/900dc5e63e764403.jpg\" alt=\"\" />";

    private String content;

    private BodyDetailAdapter adapter;
    @BindView(R.id.rv_detail)
    RecyclerView rvDetail;


    @Override
    protected void loadData() {

        adapter = new BodyDetailAdapter(null);
        rvDetail.setLayoutManager(new LinearLayoutManager(context));
        rvDetail.setAdapter(adapter);

        setHtml(imgUrl);
    }

    private void setHtml(final String detailUrl) {

        new Thread(() -> {
            content = detailUrl.replaceAll("src=\"", "src=\"https://img30.360buyimg.com");
            String[] ht = content.split("\"");
            List<String> list = new ArrayList<>();
            for (String rx : ht) {
                if (rx.contains("https")) {
                    list.add(rx);
                    Log.d("---url---",rx);
                }
            }
            adapter.setNewData(list);
        }).start();

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fm_body_detail;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void addListener() {

    }
}
